﻿using System;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Collections.Generic;

public partial class _Article : System.Web.UI.Page 
{
    protected LocalFunctions FUNC;
    private int articeID;
    
    protected string sArticle;
    protected string sTitle;
    
    protected void Page_Load(object sender, EventArgs e)
    {
        FUNC = ((Rondo)Master).FUNC;
        sendto.FUNC = FUNC;
        Calendar1.FUNC = FUNC;

        GetParameters();

        GetArticleData();
        if(FUNC.LangID==2)
            tblContent.Attributes.Add("dir", "rtl");
    }

    private void GetParameters()
    {
        articeID = Convert.ToInt32(Request.QueryString["id"]);
    }

    private void GetArticleData()
    {
        Dal.arParams.Clear();
        Dal.arParams.Add(articeID);
        DataTable DT = Dal.ExecuteDBsp("RD_GetArticle", Dal.arParams);
        if(DT!=null)
            if (DT.Rows.Count > 0)
            {
                DateTime startDate=Convert.ToDateTime(DT.Rows[0]["startdate"]);
                DateTime endDate=Convert.ToDateTime(DT.Rows[0]["enddate"]);
                
                sTitle = string.Format("{0} / {1}", FUNC.GetMonthName(startDate),
                    DT.Rows[0]["title"].ToString());
                Title = DT.Rows[0]["title"].ToString();
                lblDate.Text = string.Format("{0} - {1}", startDate.ToShortDateString(), endDate.ToShortDateString());
                lblTime.Text = string.Format("{0} - {1}", startDate.ToString("HH:mm"), endDate.ToString("HH:mm"));
                
                lblPlace.Text = DT.Rows[0]["place"].ToString();
                if (lblPlace.Text.Length == 0)
                    divPlace.Visible = false;
                
                lblPrice.Text =DT.Rows[0]["price"].ToString();
                if (lblPrice.Text.Length == 0)
                    divPrice.Visible = false;
                
                lblContacts.Text = DT.Rows[0]["contacts"].ToString();
                if (lblContacts.Text.Length == 0)
                    divContacts.Visible = false;

                sArticle = DT.Rows[0]["description"].ToString();

                string sImage = DT.Rows[0]["imagePath"].ToString();
                if (sImage.Length > 0)
                {
                    imgTitle.Src = FUNC.FullAppPath + "/Gallery/" +sImage;
                }
                else
                {
                    Dal.arParams.Clear();
                    Dal.arParams.Add(9); // vidio galery
                    Dal.arParams.Add(FUNC.LangID);
                    DataTable DTtitle = Dal.ExecuteDBsp("RD_SelectStaticPageById", Dal.arParams);
                    if (DTtitle != null)
                    {
                        if (DTtitle.Rows.Count > 0)
                        {
                            imgTitle.Src = FUNC.FullAppPath + "/Gallery/" + DTtitle.Rows[0]["imageLink"].ToString();
                        }
                    }
                }
            }
    }
}
